#include "qfloatproperty.h"

#include <QDoubleSpinBox>

QFloatProperty::QFloatProperty(SHAREDLIB::QAbstractProperty *parent):
    SHAREDLIB::QAbstractProperty(parent)
{
    connect(this,SIGNAL(showValueChanged()),this,SLOT(value_changed()));
}

void QFloatProperty::valueXML(QXmlStreamWriter *w)
{
    w->writeAttribute("value",getValue().toString());
}

QWidget* QFloatProperty::getEditor()
{
    if(attribute("editabled").toBool())
    {
        QDoubleSpinBox *b=new QDoubleSpinBox;
        b->setRange(-999999999,999999999);
        connect(b,SIGNAL(valueChanged(double)),this,SLOT(editor(double)));
        m_editor=b;
    }
    return QAbstractProperty::getEditor();
}

void QFloatProperty::editor(double value)
{
    double v=getValue().toDouble();
    if(v!=value)
    {
        setModified(true);
        setSignalValue(value);
    }
}

void QFloatProperty::value_changed()
{
    QDoubleSpinBox *b=(QDoubleSpinBox*)m_editor;
    if(b!=NULL)
    {
        b->setValue(m_value.toDouble());
    }
}
